﻿using Microsoft.Extensions.DependencyInjection;

namespace K9Nano.Dependency;

internal class DefaultIocHelper(IServiceCollection services) : IIocHelper
{
    public bool IsRegister(Type type)
    {
        return services.Any(x => x.ServiceType == type);
    }

    public IEnumerable<Type> GetRegisteredTypes(Func<Type, bool> filter)
    {
        return services.Where(x => filter(x.ServiceType))
            .Select(x => x.ImplementationType ?? x.KeyedImplementationType)
            .Cast<Type>();
    }
}